var ApplicationValues = {
	element_color : "#ffffbb",
	dialog : new Dialog()
};
var Application = function(a) {
	a = a || {};
	if (!(a.id && a.width && a.height)) {
		return
	}
	this._width = a.width;
	this._height = a.height;
	this._generateStructure(a.id);
	this._selected = null;
	this._diagrams = [];
	this._tabs = [];;
};
var _acceptedDiagrams = [];
var _acceptedElementsUML = [];
var _genericMenu = [];
var _specificMenu = [];
var _stereotypes = [];
var _metaclass = [];
var _delProfileElement = function(b) {
	if (b.getType() == "UMLMetaclass") {
		b.interaction(false);
		for ( var a in _metaclass) {
			if (_metaclass[a] == b) {
				_metaclass.splice(a, 1);
				_metaclass[a].interaction(false);
			}
		}
	}
	if (b.getType() == "UMLStereotype") {
		for ( var a in _stereotypes) {
			if (_stereotypes[a] == b) {
				_stereotypes.splice(a, 1);
			}
		}
	}
};
Application.prototype._generateStructure = function(b) {
	var g = document.getElementById(b);
	var d = document.createElement("div");
	d.setAttribute("id", "ud_tools_div");
	var f = document.createElement("ul");
	f.setAttribute("id", "ud_tools_ul1");
	var e = document.createElement("ul");
	e.setAttribute("id", "ud_tools_ul2");
	d.appendChild(f);
	d.appendChild(e);
	g.appendChild(d);
	this._tools_div = d;
	this._tools_ul1 = f;
	this._tools_ul2 = e;
	var l = document.createElement("div");
	l.setAttribute("id", "ud_container_div");
	var n = document.createElement("div");
	n.setAttribute("id", "ud_selector_div");
	var a = document.createElement("ul");
	a.setAttribute("id", "ud_selector_ul");
	n.appendChild(a);
	l.appendChild(n);
	this._selector_ul = a;
	var j = document.createElement("div");
	j.setAttribute("id", "ud_diagram_div");
	j.setAttribute("class", "ud_diagram_div");
	j.style.width = this._width + "px";
	j.style.height = this._height + "px";
	this._diagram_div = j;
	l.appendChild(j);
	g.appendChild(l);
	var c;
	c = document.createElement("canvas");
	c.setAttribute("class", "ud_diagram_canvas");
	c.width = this._width;
	c.height = this._height;
	j.appendChild(c);
	this._mainContext = c.getContext("2d");
	this._mainCanvas = c;
	c = document.createElement("canvas");
	c.setAttribute("class", "ud_diagram_canvas");
	c.width = this._width;
	c.height = this._height;
	c.onmousedown = function() {
		return false;
	};
	j.appendChild(c);
	this._motionContext = c.getContext("2d");
	var h = document.createElement("div");
	h.setAttribute("id", "ud_update_div");
	h.title = "apply changes in profile to diagrams";
	h.style.right = 15 + "px";
	h.style.display = "none";
	j.appendChild(h);
	var k = this;
	h.onclick = function() {
		ApplicationValues.dialog._text = "Do you want to update the diagrams according to the changes of the profile?";
		ApplicationValues.dialog._cancelable = true;
		if (k._selected && k._diagrams[k._selected].getType() == "UMLProfile") {
			ApplicationValues.dialog.show(function() {
				var o = [];
				for (i in k._diagrams) {
					if (k._diagrams[i].getType() != "UMLProfile") {
						o.push(k._diagrams[i]);
					}
				}
				k._diagrams[k._selected].updateProfile(o);
			});
		}
	};
	/**注释以下代码，使之不能编辑 删除**/
//	var m = document.createElement("div");
//	m.setAttribute("id", "ud_delete_div");
//	j.appendChild(m);
//	var k = this;
//	m.onclick = function() {
//		ApplicationValues.dialog._text = 'Do you want to delete the diagram "'
//				+ k._diagrams[k._selected].getName() + '"?';
//		ApplicationValues.dialog._cancelable = true;
//		if (k._selected) {
//			ApplicationValues.dialog.show(function() {
//				k._delDiagram();
//				k._generateSpecificMenu()
//			})
//		}
//	}
};
Application.prototype._changeTabName = function(c) {
	var e = this._diagrams[c].getName();
	if (e.length > 20) {
		e = e.substring(0, 17);
		e += "...";
	}
	var b = this._tabs[c];
	var d = b.firstChild;
	var a = d.firstChild;
	d.removeChild(a);
	d.appendChild(document.createTextNode(e));
};
Application.prototype._addTab = function(b) {
	var a = document.createElement("li");
	var d = document.createElement("a");
	d.appendChild(document.createTextNode(""));
	a.appendChild(d);
	this._selector_ul.appendChild(a);
	this._tabs[b] = a;
	var c = this;
	var e = c._diagrams[b];
	var f = "DomainEntiy";
	e.setName(f);
	c._changeTabName(b);
	e.draw();
	this._changeTabName(b);
};
Application.prototype._delTab = function(a) {
	this._selector_ul.removeChild(this._tabs[a]);
	delete this._tabs[a];
};
Application.prototype._generateIndex = function() {
	var a = Math.random();
	while (true) {
		if (a in this._diagrams) {
			a = Math.random();
		} else {
			return a;
		}
	}
};

Application.prototype.addDiagram = function(a) {
	var b = this._generateIndex();
	a.initialize(b, this._diagram_div, this._mainContext, this._motionContext,
			this._width, this._height);
	a.interaction(false);
	this._diagrams[b] = a;
	this._diagrams[b].setUpdateHeightCanvas(true);
	if (a.isVisible()) {
		this._addTab(b);
	}
	this._selectDiagram(b);
};
Application.prototype._delDiagram = function() {
	var a = this._selected;
	if (a) {
		this._diagrams[a].interaction(false);
		this._delTab(a);
		if (this._diagrams[a].getType() == "UMLProfile") {
			var c = [];
			for (b in this._diagrams) {
				if (this._diagrams[b].getType() != "UMLProfile") {
					c.push(this._diagrams[b]);
				}
			}
			this._diagrams[a].removeProfile(c);
			for (b = 0; b < this._diagrams[a]._nodes.length; b++) {
				_delProfileElement(this._diagrams[a]._nodes[b])
			}
		}
		delete this._diagrams[a];
		this._selected = null;
		var b;
		for (b in this._diagrams) {
			if (this._diagrams[b]._visible) {
				this._selectDiagram(b);
				return;
			}
		}
		this._clearCanvas();
	}
};
Application.prototype._clearCanvas = function() {
	this._mainContext.clearRect(0, 0, this._width, this._height);
	this._motionContext.clearRect(0, 0, this._width, this._height);
};
Application.prototype._selectDiagram = function(b) {
	if (this._selected && this._diagrams[b].isVisible()) {
		this._diagrams[this._selected].interaction(false);
		this._tabs[this._selected].removeAttribute("class");
	}
	this._clearCanvas();
	this._diagrams[b].draw();
	/**设置为不可编辑**/
	this._diagrams[b].interaction(false);
	if (this._diagrams[b].isVisible()) {
		this._selected = b;
		this._tabs[b].setAttribute("class", "active");
		//this._generateSpecificMenu();
		var a = document.getElementById("ud_update_div");
		if (this._diagrams[b].getType() == "UMLProfile") {
			a.style.display = "block";
		} else {
			a.style.display = "none";
		}
	}
};
Application.prototype._getDiagramImage = function() {
	if (this._selected) {
		this._diagrams[this._selected].stopEvents();
		this._diagrams[this._selected].draw();
		return this._mainCanvas.toDataURL("image/png");
	}
};

Application.prototype._generateDiagram = function(str) {
	var p = this;
	this._active = false;
	var h = document.createElement("div");
		//add
		var m = this;
		m.setXMLString(str);
		//document.body.removeChild(h);
		//add
		h.style.top = (window.innerHeight - 50) / 2 + "px";
		h.style.left = (window.innerWidth - 50) / 2 + "px";
}
Application.prototype.updateBackgroundElementDiagram = function() {
	for (i in this._diagrams) {
		this._diagrams[i].setBackgroundNodes(ApplicationValues.element_color)
	}
};
Application.prototype.getXML = function() {
	var b = (new DOMParser()).parseFromString("<umldiagrams/>", "text/xml");
	var d = b.getElementsByTagName("umldiagrams")[0];
	var a;
	var c;
	for (c in this._diagrams) {
		a = this._diagrams[c].getXML(b);
		d.appendChild(a)
	}
	return b
};
Application.prototype.getCurrentXML = function() {
	var b = (new DOMParser()).parseFromString("<umldiagrams/>", "text/xml");
	var c = b.getElementsByTagName("umldiagrams")[0];
	var a;
	a = this._diagrams[this._selected].getXML(b);
	c.appendChild(a);
	return b;
};
Application.prototype.getXMLString = function() {
	return (new XMLSerializer()).serializeToString(this.getXML());
};
Application.prototype.getCurrentXMLString = function() {
	return (new XMLSerializer()).serializeToString(this.getCurrentXML())
};
Application.prototype.setXML = function(xml) {
	var application = xml.getElementsByTagName("umldiagrams")[0];
	if (!application) {
		alert("Not found a valid XML string");
		return
	}
	var xmlnodes = application.childNodes;
	var aux, nodeName;
	var i, j;
	for (i = 0; i < xmlnodes.length; i++) {
		nodeName = xmlnodes[i].nodeName;
		for (j in _acceptedDiagrams) {
			if (nodeName == _acceptedDiagrams[j]) {
				aux = eval("new " + nodeName + "()");
				if (nodeName != "UMLProfile") {
					aux.setXML(xmlnodes[i], _stereotypes)
				} else {
					aux.setXML(xmlnodes[i], this._diagrams,
							_acceptedElementsUML);
					this.storeInformationProfile(aux)
				}
				this.addDiagram(aux);
				break;
			}
		}
	}
};
Application.prototype.storeInformationProfile = function(b) {
	var c = b.getElements();
	for ( var a = 0; a < c[0].length; a++) {
		_metaclass.push(c[0][a])
	}
	for (a = 0; a < c[1].length; a++) {
		_stereotypes.push(c[1][a])
	}
};
Application.prototype.foundInArray = function(c, b) {
	for ( var a = 0; a < c.length; a++) {
		if (b == c[a]) {
			return true
		}
	}
	return false
};
Application.prototype.setXMLString = function(a) {
	a = a.replace(/\n/gi, "");
	this.setXML((new DOMParser()).parseFromString(a, "text/xml"))
};
_acceptedDiagrams.push("UMLClassDiagram");
_acceptedElementsUML.push([ "Class", "UMLClass" ],
		[ "Data Type", "UMLDataType" ], [ "Association N-ary",
				"UMLNAssociation" ], [ "Component (Class diagram)",
				"UMLComponent" ], [ "Interface Extended",
				"UMLInterfaceExtended" ], [ "UMLPackage", "Package" ], [
				"Package Container", "UMLPackageContainer" ], [
				"Generalization Set", "UMLGeneralizationSet" ]);
_genericMenu.push([ "New class diagram", function(a) {
	a.addDiagram(new UMLClassDiagram({
		backgroundNodes : ApplicationValues.element_color
	}))
}, 0, "UMLClassDiagram" ]);
_specificMenu.UMLClassDiagram = [ [ "Class", function(b, a, d) {
	var c = new UMLClass({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(c)
}, 1, "UMLClass" ], [ "DataType", function(b, a, d) {
	var c = new UMLDataType({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(c)
}, 1, "UMLDataType" ], [ "Component", function(b, a, d) {
	var c = new UMLComponent({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(c);
}, 1, "UMLComponent" ], [ "Interface", function(b, a, d) {
	var c = new UMLInterfaceExtended({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(c);
}, 1, "UMLInterfaceExtended" ], [ "Package", function(b, a, d) {
	var c = new UMLPackage({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(c);
}, 1, "UMLPackage" ], [ "Package container", function(b, a, d) {
	var c = new UMLPackageContainer({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(c)
}, 1, "UMLPackageContainer" ], [ "N-ary Association", function(b, a, d) {
	var c = new UMLNAssociation({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(c)
}, 1, "UMLNAssociation" ], [ "Generalization", function(e, d, g, c, f) {
	var b = e.getElementByPoint(d, g);
	var a = e.getElementByPoint(c, f);
	if (b && b.getType() == "UMLGeneralizationSet") {
		b.addElement(a)
	} else {
		if (a && a.getType() == "UMLGeneralizationSet") {
			a.addElement(b)
		} else {
			e.addRelationFromPoints(new UMLGeneralization(), d, g, c, f)
		}
	}
}, 2, "UMLGeneralization" ], [ "Generalization Set", function(c, b, e, a, d) {
	c.addRelationFromPoints(new UMLGeneralizationSet(), b, e, a, d)
}, 2, "UMLGeneralizationSet" ], [ "Association", function(e, d, g, c, f) {
	var b = e.getElementByPoint(d, g);
	var a = e.getElementByPoint(c, f);
	if (b && b.getType() == "UMLNAssociation") {
		b.addElement(a);
		e.addElement(b.getRelation(a))
	} else {
		if (a && a.getType() == "UMLNAssociation") {
			a.addElement(b);
			e.addElement(a.getRelation(b))
		} else {
			e.addRelationFromPoints(new UMLAssociation(), d, g, c, f)
		}
	}
}, 2, "UMLAssociation" ], [ "Aggregation", function(c, b, e, a, d) {
	c.addRelationFromPoints(new UMLAggregation(), b, e, a, d)
}, 2, "UMLAggregation" ], [ "Composition", function(c, b, e, a, d) {
	c.addRelationFromPoints(new UMLComposition(), b, e, a, d)
}, 2, "UMLComposition" ], [ "Dependency", function(c, b, e, a, d) {
	c.addRelationFromPoints(new UMLDependency(), b, e, a, d)
}, 2, "UMLDependency" ], [ "Realization", function(c, b, e, a, d) {
	c.addRelationFromPoints(new UMLRealization(), b, e, a, d)
}, 2, "UMLRealization" ], [ "Usage", function(c, b, e, a, d) {
	c.addRelationFromPoints(new UMLUsage(), b, e, a, d)
}, 2, "UMLUsage" ], [ "Package merge", function(c, b, e, a, d) {
	c.addRelationFromPoints(new UMLPackageMerge(), b, e, a, d)
}, 2, "UMLPackageMerge" ], [ "Package public import", function(c, b, e, a, d) {
	c.addRelationFromPoints(new UMLPackagePublicImport(), b, e, a, d)
}, 2, "UMLPackagePublicImport" ],
		[ "Package private import", function(c, b, e, a, d) {
			c.addRelationFromPoints(new UMLPackagePrivateImport(), b, e, a, d)
		}, 2, "UMLPackagePrivateImport" ] ];
_acceptedDiagrams.push("UMLUseCaseDiagram");
_acceptedElementsUML.push([ "Actor", "UMLActor" ],
		[ "Use Case", "UMLUseCase" ],
		[ "UseCaseExtended", "UMLUseCaseExtended" ], [ "System", "UMLSystem" ],
		[ "SubSystem", "UMLSubSystem" ]);
_genericMenu.push([ "New use case diagram", function(a) {
	a.addDiagram(new UMLUseCaseDiagram({
		backgroundNodes : ApplicationValues.element_color
	}))
}, 0, "UMLUseCaseDiagram" ]);
_specificMenu.UMLUseCaseDiagram = [ [ "Actor", function(b, a, d) {
	var c = new UMLActor({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(c)
}, 1, "UMLActor" ], [ "Use case", function(b, a, d) {
	var c = new UMLUseCase({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(c)
}, 1, "UMLUseCase" ], [ "UseCaseExtended", function(b, a, d) {
	var c = new UMLUseCaseExtended({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(c)
}, 1, "UMLUseCaseExtended" ], [ "System", function(b, a, d) {
	var c = new UMLSystem({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(c)
}, 1, "UMLSystem" ], [ "SubSystem", function(b, a, d) {
	var c = new UMLSubSystem({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(c)
}, 1, "UMLSubSystem" ], [ "Communication", function(c, b, e, a, d) {
	c.addRelationFromPoints(new UMLCommunication(), b, e, a, d)
}, 2, "UMLCommunication" ], [ "Extend", function(c, b, e, a, d) {
	c.addRelationFromPoints(new UMLExtend(), b, e, a, d)
}, 2, "UMLExtend" ], [ "Include", function(c, b, e, a, d) {
	c.addRelationFromPoints(new UMLInclude(), b, e, a, d)
}, 2, "UMLInclude" ], [ "Generalization", function(e, d, g, c, f) {
	var b = e.getElementByPoint(d, g);
	var a = e.getElementByPoint(c, f);
	if (b && b.getType() == "UMLGeneralizationSet") {
		b.addElement(a);
		e.addElement(b.getRelation(a))
	} else {
		if (a && a.getType() == "UMLGeneralizationSet") {
			a.addElement(b);
			e.addElement(a.getRelation(b))
		} else {
			e.addRelationFromPoints(new UMLGeneralization(), d, g, c, f)
		}
	}
}, 2, "UMLGeneralization" ], [ "Generalization Set", function(c, b, e, a, d) {
	c.addRelationFromPoints(new UMLGeneralizationSet(), b, e, a, d)
}, 2, "UMLGeneralizationSet" ], ];
_acceptedDiagrams.push("UMLComponentDiagram");
_acceptedElementsUML.push(
		[ "Component (Component diagram)", "UMLComComponent" ], [ "Interface",
				"UMLInterface" ]);
_genericMenu.push([ "New component diagram", function(a) {
	a.addDiagram(new UMLComponentDiagram({
		backgroundNodes : ApplicationValues.element_color
	}))
}, 0, "UMLComponentDiagram" ]);
_specificMenu.UMLComponentDiagram = [
		[ "Package", function(b, a, d) {
			var c = new UMLPackage({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLPackage" ],
		[ "Package container", function(b, a, d) {
			var c = new UMLPackageContainer({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLPackageContainer" ],
		[ "Component", function(b, a, d) {
			var c = new UMLComComponent({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLComponent" ],
		[ "Add Port", function(b, a, e) {
			var d = b.getElementByPoint(a, e);
			if (d != null && d.getType() == "UMLComComponent") {
				var c = new UMLPort({
					stereotypes : _stereotypes
				});
				d.addPort(c);
			}
		}, 1, "UMLPort" ],
		[ "Interface", function(b, a, d) {
			var c = new UMLInterface({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c);
		}, 1, "UMLInterface" ],
		[ "Interface Extended", function(b, a, d) {
			var c = new UMLInterfaceExtended({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c);
		}, 1, "UMLInterfaceExtended" ],
		[ "Interface usage", function(c, b, e, a, d) {
			c.addRelationFromPoints(new UMLInterfaceUsage(), b, e, a, d)
		}, 2, "UMLInterfaceUsage" ],
		[ "Interface realization", function(c, b, e, a, d) {
			c.addRelationFromPoints(new UMLInterfaceRealization(), b, e, a, d)
		}, 2, "UMLInterfaceRealization" ],
		[
				"Generalization",
				function(e, d, g, c, f) {
					var b = e.getElementByPoint(d, g);
					var a = e.getElementByPoint(c, f);
					if (b && b.getType() == "UMLGeneralizationSet") {
						b.addElement(a);
						e.addElement(b.getRelation(a));
					} else {
						if (a && a.getType() == "UMLGeneralizationSet") {
							a.addElement(b);
							e.addElement(a.getRelation(b))
						} else {
							e.addRelationFromPoints(new UMLGeneralization(), d,
									g, c, f);
						}
					}
				}, 2, "UMLGeneralization" ],
		[ "Generalization Set", function(c, b, e, a, d) {
			c.addRelationFromPoints(new UMLGeneralizationSet(), b, e, a, d)
		}, 2, "UMLGeneralizationSet" ],
		[ "Component Realization", function(c, b, e, a, d) {
			c.addRelationFromPoints(new UMLRealization(), b, e, a, d)
		}, 2, "UMLRealization" ], [ "Connector", function(c, b, e, a, d) {
			c.addRelationFromPoints(new UMLConnector(), b, e, a, d)
		}, 2, "UMLConnector" ], ];
_acceptedDiagrams.push("UMLSequenceDiagram");
_acceptedElementsUML.push([ "Lifeline", "UMLLifeline" ], [ "Option",
		"UMLOption" ], [ "Alternative", "UMLAlternative" ],
		[ "Loop", "UMLLoop" ], [ "Break", "UMLBreak" ]);
_genericMenu.push([ "New sequence diagram", function(a) {
	a.addDiagram(new UMLSequenceDiagram({
		backgroundNodes : ApplicationValues.element_color
	}))
}, 0, "UMLSequenceDiagram" ]);
_specificMenu.UMLSequenceDiagram = [
		[ "Lifeline", function(b, a, d) {
			var c = new UMLLifeline({
				x : a,
				y : 70,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLLifeline" ],
		[
				"Create",
				function(e, d, g, c, f) {
					var b = e.getElementByPoint(d, g);
					var a = e.getElementByPoint(c, f);
					if (b
							&& a
							&& b != a
							&& (b.getType() == "UMLLifeline" || b.getType() == "TimeInterval")
							&& a.getType() == "UMLLifeline" && !a.getCreate()) {
						e.addElement(new UMLCreate({
							a : b,
							b : a,
							y : g
						}))
					}
				}, 2, "UMLCreate" ],
		[
				"Destroy",
				function(e, d, g, c, f) {
					var b = e.getElementByPoint(d, g);
					var a = e.getElementByPoint(c, f);
					if (b
							&& a
							&& b != a
							&& (b.getType() == "UMLLifeline" || b.getType() == "TimeInterval")
							&& a.getType() == "UMLLifeline" && !a.getDelete()) {
						e.addElement(new UMLDestroy({
							a : b,
							b : a,
							y : g
						}))
					}
				}, 2, "UMLDestroy" ],
		[ "Option", function(b, a, d) {
			var c = new UMLOption({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLInteraction" ],
		[ "Alternative", function(b, a, d) {
			var c = new UMLAlternative({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLInteraction" ],
		[ "Loop", function(b, a, d) {
			var c = new UMLLoop({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLInteraction" ],
		[ "Break", function(b, a, d) {
			var c = new UMLBreak({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLInteraction" ],
		[
				"Send Message",
				function(e, d, g, c, f) {
					var b = e.getElementByPoint(d, g);
					var a = e.getElementByPoint(c, f);
					if (b
							&& a
							&& (b.getType() == "UMLLifeline" || b.getType() == "TimeInterval")
							&& (a.getType() == "UMLLifeline" || a.getType() == "TimeInterval")) {
						e.addElement(new UMLSendMessage({
							a : b,
							b : a,
							y : g
						}))
					}
				}, 2, "UMLSendMessage" ],
		[
				"Call Message",
				function(e, d, g, c, f) {
					var b = e.getElementByPoint(d, g);
					var a = e.getElementByPoint(c, f);
					if (b
							&& a
							&& (b.getType() == "UMLLifeline" || b.getType() == "TimeInterval")
							&& (a.getType() == "UMLLifeline" || a.getType() == "TimeInterval")) {
						e.addElement(new UMLCallMessage({
							a : b,
							b : a,
							y : g
						}))
					}
				}, 2, "UMLCallMessage" ],
		[
				"Reply Message",
				function(e, d, g, c, f) {
					var b = e.getElementByPoint(d, g);
					var a = e.getElementByPoint(c, f);
					if (b != a
							&& b != null
							&& (b.getType() == "UMLLifeline" || b.getType() == "TimeInterval")
							&& (a.getType() == "UMLLifeline" || a.getType() == "TimeInterval")) {
						e.addElement(new UMLReplyMessage({
							a : b,
							b : a,
							y : g
						}))
					}
				}, 2, "UMLReplyMessage" ],
		[
				"Delete Message",
				function(e, d, g, c, f) {
					var b = e.getElementByPoint(d, g);
					var a = e.getElementByPoint(c, f);
					if (b
							&& a
							&& b != a
							&& (b.getType() == "UMLLifeline" || b.getType() == "TimeInterval")
							&& a.getType() == "UMLLifeline" && !a.getDelete()) {
						e.addElement(new UMLDeleteMessage({
							a : b,
							b : a,
							y : g
						}))
					}
				}, 2, "UMLDeleteMessage" ], ];
_acceptedDiagrams.push("UMLStateMachineDiagram");
_acceptedElementsUML.push([ "SimpleState", "UMLSimpleState" ], [
		"CompositeState", "UMLCompositeState" ], [ "VerticalRegion",
		"UMLVerticalRegion" ], [ "HorizontalRegion", "UMLHorizontalRegion" ]);
_genericMenu.push([ "New state machine diagram", function(a) {
	a.addDiagram(new UMLStateMachineDiagram({
		backgroundNodes : ApplicationValues.element_color
	}))
}, 0, "UMLStateMachineDiagram" ]);
_specificMenu.UMLStateMachineDiagram = [ [ "Initial State", function(b, a, c) {
	b.addElement(new UMLInitialPseudostate({
		x : a,
		y : c
	}))
}, 1, "UMLInitialPseudostate" ], [ "Final State", function(b, a, c) {
	b.addElement(new UMLFinalState({
		x : a,
		y : c
	}))
}, 1, "UMLFinalState" ], [ "Terminate", function(b, a, d) {
	var c = new UMLTerminate({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(new UMLTerminate({
		x : a,
		y : d
	}))
}, 1, "UMLTerminate" ], [ "Entry Point", function(b, a, d) {
	var c = new UMLEntryPoint({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(c)
}, 1, "UMLEntryPoint" ], [ "Exit Point", function(b, a, d) {
	var c = new UMLExitPoint({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(c)
}, 1, "UMLExitPoint" ], [ "Junction", function(b, a, d) {
	var c = new UMLJunction({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(c)
}, 1, "UMLJunction" ], [ "Simple State", function(b, a, d) {
	var c = new UMLSimpleState({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(c)
}, 1, "UMLSimpleState" ], [ "Composite State", function(b, a, d) {
	var c = new UMLCompositeState({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(c)
}, 1, "UMLCompositeState" ], [ "Vertical Region", function(b, a, d) {
	var c = new UMLVerticalRegion({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(c)
}, 1, "UMLVerticalRegion" ], [ "Horizontal Region", function(b, a, d) {
	var c = new UMLHorizontalRegion({
		x : a,
		y : d,
		stereotypes : _stereotypes
	});
	b.addElement(c)
}, 1, "UMLHorizontalRegion" ], [ "Transition", function(c, b, e, a, d) {
	c.addRelationFromPoints(new UMLTransition(), b, e, a, d)
}, 2, "UMLTransition" ] ];
_acceptedDiagrams.push("UMLActivityDiagram");
_acceptedElementsUML.push([ "AcceptEventAction", "UMLAcceptEventAction" ], [
		"TimeEvent", "UMLTimeEvent" ], [ "SendSignalAction",
		"UMLSendSignalAction" ], [ "Action", "UMLAction" ], [ "ObjectNode",
		"UMLObject" ], [ "Activity", "UMLActivity" ], [ "DataStore",
		"UMLDataStore" ], [ "Connector", "UMLConnectorActivity" ], [
		"HorizontalSwimlane", "UMLHorizontalSwimlane" ], [ "VerticalSwimlane",
		"UMLVerticalSwimlane" ], [ "Horizontal Hierarchical Swimlane",
		"UMLHorizontalHierarchicalSwimlane" ], [
		"Vertical Hierarchical Swimlane", "UMLVerticalHierarchicalSwimlane" ]);
_genericMenu.push([ "New activity diagram", function(a) {
	a.addDiagram(new UMLActivityDiagram({
		backgroundNodes : ApplicationValues.element_color
	}))
}, 0, "UMLActivityDiagram" ]);
_specificMenu.UMLActivityDiagram = [
		[ "AcceptEventAction", function(b, a, d) {
			var c = new UMLAcceptEventAction({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLAcceptEventAction" ],
		[ "TimeEvent", function(b, a, d) {
			var c = new UMLTimeEvent({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLTimeEvent" ],
		[ "SendSignalAction", function(b, a, d) {
			var c = new UMLSendSignalAction({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLSendSignalAction" ],
		[ "Action", function(b, a, d) {
			var c = new UMLAction({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLAction" ],
		[ "ObjectNode", function(b, a, d) {
			var c = new UMLObject({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLObject" ],
		[ "Activity", function(b, a, d) {
			var c = new UMLActivity({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLActivity" ],
		[ "DataStore", function(b, a, d) {
			var c = new UMLDataStore({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLDataStore" ],
		[ "Connector", function(b, a, d) {
			var c = new UMLConnectorActivity({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLConnector2" ],
		[ "HorizontalSwimlane", function(b, a, c) {
			b.addElement(new UMLHorizontalSwimlane({
				x : a,
				y : c
			}))
		}, 1, "UMLHorizontalSwimlane" ],
		[ "VerticalSwimlane", function(b, a, c) {
			b.addElement(new UMLVerticalSwimlane({
				x : a,
				y : c
			}))
		}, 1, "UMLVerticalSwimlane" ],
		[ "HorizontalHierarchicalSwimlane", function(b, a, d) {
			var c = new UMLHorizontalHierarchicalSwimlane({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLHorizontalHierarchicalSwimlane" ],
		[ "VerticalHierarchicalSwimlane", function(b, a, d) {
			var c = new UMLVerticalHierarchicalSwimlane({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLVerticalHierarchicalSwimlane" ],
		[ "Add Pin", function(b, a, e) {
			var d = b.getElementByPoint(a, e);
			if (d != null && d.getType() == "UMLAction") {
				var c = new UMLPin({
					stereotypes : _stereotypes
				});
				d.addPort(c)
			}
		}, 1, "UMLPin" ],
		[ "Parameter Node", function(b, a, e) {
			var d = b.getElementByPoint(a, e);
			if (d != null && d.getType() == "UMLActivity") {
				var c = new UMLParameterNode({
					stereotypes : _stereotypes
				});
				d.addPort(c)
			}
		}, 1, "UMLParameterNode" ],
		[ "Expansion Node", function(b, a, e) {
			var d = b.getElementByPoint(a, e);
			if (d != null && d.getType() == "UMLAction") {
				var c = new UMLExpansionNode({
					stereotypes : _stereotypes
				});
				d.addPort(c)
			}
		}, 1, "UMLExpansionNode" ],
		[
				"Flow/Edge",
				function(c, b, f, a, e) {
					var j = c.getElementByPoint(b, f);
					var h = c.getElementByPoint(a, e);
					var g = 0;
					var d = 0;
					if (j instanceof NodeForkJoin) {
						g = (j._quadrant == 1) ? (b - j._x) : 0;
						d = (j._quadrant == 2) ? (f - j._y) : 0
					} else {
						if (h instanceof NodeForkJoin) {
							g = (h._quadrant == 1) ? (a - h._x) : 0;
							d = (h._quadrant == 2) ? (e - h._y) : 0
						}
					}
					if (j
							&& h
							&& !(j instanceof NodeForkJoin && h instanceof NodeForkJoin)) {
						c.addElement(new UMLFlow({
							a : j,
							b : h,
							y : d,
							x : g
						}))
					}
				}, 2, "UMLFlow" ],
		[ "ExceptionHandler", function(c, b, e, a, d) {
			c.addRelationFromPoints(new UMLExceptionHandler(), b, e, a, d)
		}, 2, "UMLExceptionHandler" ], [ "ActivityFinal", function(b, a, c) {
			b.addElement(new UMLActivityFinal({
				x : a,
				y : c
			}))
		}, 1, "UMLActivityFinal" ], [ "InitialNode", function(b, a, c) {
			b.addElement(new UMLInitialNode({
				x : a,
				y : c
			}))
		}, 1, "UMLInitialNode" ], [ "FlowFinal", function(b, a, d) {
			var c = new UMLFlowFinal({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLFlowFinal" ], [ "Decision/Merge Node", function(b, a, d) {
			var c = new UMLDecision_MergeNode({
				x : a,
				y : d,
				stereotypes : _stereotypes
			});
			b.addElement(c)
		}, 1, "UMLDecision_MergeNode" ], [ "Fork/Join Node", function(b, a, c) {
			b.addElement(new UMLFork_JoinNode({
				x : a,
				y : c
			}))
		}, 1, "UMLFork_JoinNode" ] ];
_acceptedDiagrams.push("UMLProfile");
_genericMenu.push([ "New profile", function(a) {
	a.addDiagram(new UMLProfile({
		backgroundNodes : ApplicationValues.element_color
	}))
}, 0, "UMLProfile" ]);